import {
    getTopBanners,
    getHotRecommends,
    getNewAlbums,
    getTopList
} from '@/services/recommend';

const changeTopBannerAction = (res) => ({
    type: "banners",
    banners: res.banners
});

const changeHotRecommendsAction = (res) => ({
    type: "hotRecommends",
    hotRecommends: res.result
});

const changeNewAlbumsAction = (res) => ({
    type: "newAlbums",
    newAlbums: res.weekData
})

const changeUpRankingAction = (res) => ({
    type: "upRanking",
    upRanking: res.playlist
})

const changeNewRankingAction = (res) => ({
    type: "newRanking",
    newRanking: res.playlist
})

const changeOriginRankingAction = (res) => ({
    type: "originRanking",
    originRanking: res.playlist
})

export const getTopBannerAction = () => {
    return dispatch => {
        getTopBanners().then(res => {
            dispatch(changeTopBannerAction(res));
        })
    }
};

export const getHotRecommendsAction = (limit) => {
    return dispatch => {
        getHotRecommends(limit).then(res => {
            dispatch(changeHotRecommendsAction(res));
        })
    }
};

export const getNewAlbumsAction = (limit) => {
    return dispatch => {
        getNewAlbums(limit).then(res => {
            dispatch(changeNewAlbumsAction(res));
        })
    }
};

export const getTopListAction = (idx) => {
    return dispatch => {
        getTopList(idx).then(res => {
            switch (idx) {
                case 0:
                    dispatch(changeUpRankingAction(res));
                    break;
                case 2:
                    dispatch(changeNewRankingAction(res));
                    break;
                case 3:
                    dispatch(changeOriginRankingAction(res));
                    break;
                default:
            }
        });
    }
}